package com.gz.logistics.library.listener;

import com.gz.logistics.library.pojo.OrderInfo;
import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * author wanner1991
 */
public abstract class GetQRCodeOrderDetailListener extends BaseListener{
    private String TAG = GetQueryorderListener.class.getSimpleName();
    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_STATUS);
            String msg = response.getString(Constants.REQ_MSG);
            switch(status){
                case Constants.REQ_OK:
                    JSONObject jsonObject = response.getJSONObject(Constants.REQ_RESULT);
                    onResponseSuccess(OrderInfo.parse(jsonObject));
                    break;
                case Constants.REQ_QRCODE_THIS_ORDER_IS_NOT_BELONG_TO_THIS_USER:
                    onNotBelongToThisUser();
                    break;
                case Constants.REQ_QRCODE_THIS_ORDER_IS_NOT_EXIST:
                    onOrderInfoNotExist();
                    break;
                default:
                    onResponseFailed();
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }

    /**
     * 订单信息不存在
     */
    public abstract void onOrderInfoNotExist();

    /**
     * 该订单不属于该用户
     */
    public abstract void onNotBelongToThisUser();
    public abstract void onResponseSuccess(OrderInfo orderDetail);

    @Override
    public void onFailure(int statusCode, Header[] headers,
                          Throwable throwable, JSONObject errorResponse) {
        onResponseFailed();
        CrashHandler.e(throwable);
    }

    @Override
    public void onNoMoreData() {

    }

    @Override
    public void onOffline() {

    }


}
